package com.bawei.a2010douyin.ui.tuijian;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawei.a2010douyin.R;
import com.bawei.a2010douyin.base.mvp.BaseView;
import com.bawei.a2010douyin.base.utils.GlideUtils;
import com.bawei.a2010douyin.entity.VideoEntity;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import androidx.annotation.NonNull;

//MultiItem： 多个item
public class VideoAdapter extends BaseMultiItemQuickAdapter<VideoEntity, BaseViewHolder> {
    //构造：添加对应的item布局
    public VideoAdapter() {
        addItemType(0, R.layout.item_video);
        addItemType(1,R.layout.item_video_zhibo);
        addItemType(2,R.layout.item_video_full);
    }
    //判断type展示对应的UI
    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, VideoEntity videoEntity) {
        switch (videoEntity.getItemType()){
            case 0://短视频
            case 2://全凭观看
            {
                //视频播放器
                StandardGSYVideoPlayer standardGSYVideoPlayer = baseViewHolder.getView(R.id.gsy);
                standardGSYVideoPlayer.setUp(videoEntity.getVideopath(),true,"");
                standardGSYVideoPlayer.getBackButton().setVisibility(View.GONE);
                //头像
                ImageView ivUser = baseViewHolder.getView(R.id.iv_user);
                GlideUtils.getInstance().loadCircleImage(getContext(),videoEntity.getHeadpath(),ivUser);
                //转盘
                ImageView ivZhuan = baseViewHolder.getView(R.id.iv_zhuan);
                GlideUtils.getInstance().loadCircleImage(getContext(),videoEntity.getHeadpath(),ivZhuan);
                //旋转动画

                ObjectAnimator rotation = ObjectAnimator.ofFloat(ivZhuan, "Rotation", 0, 360);
                rotation.setDuration(1000);
                rotation.setRepeatCount(ValueAnimator.INFINITE);//次数：无限
                rotation.setInterpolator(new LinearInterpolator());//差值器：匀速
                rotation.start();

                //文本
                baseViewHolder.setText(R.id.tv_pao,videoEntity.getAuthname()+"的原创作品");
                baseViewHolder.setText(R.id.tv_caption,videoEntity.getCaption()+"");
                baseViewHolder.setText(R.id.tv_username,videoEntity.getAuthname()+"");
                baseViewHolder.setText(R.id.tv_address,videoEntity.getAddress()+"");
                //跑马灯:必须请求获得焦点，跑马灯才能跑起来
                TextView tvPao = baseViewHolder.getView(R.id.tv_pao);
                tvPao.requestFocus();

                //判断用户是否点赞过
                ImageView ivZan = baseViewHolder.getView(R.id.iv_dianzan);
                if(videoEntity.getDianzan() == 1){//点赞过
                    ivZan.setImageResource(R.drawable.ic_xihuanred);
                }else{
                    ivZan.setImageResource(R.drawable.ic_xihuan);
                }
                //判断是否关注过
                ImageView ivAdd = baseViewHolder.getView(R.id.iv_add);
                if(videoEntity.getGuanzhu() == 1){//关注过
                    ivAdd.setVisibility(View.GONE);
                }else{
                    ivAdd.setVisibility(View.VISIBLE);
                }



            }
                break;
            case 1://直播
            {
                //视频播放器
                StandardGSYVideoPlayer standardGSYVideoPlayer = baseViewHolder.getView(R.id.gsy);
                standardGSYVideoPlayer.setUp(videoEntity.getVideopath(),true,"");
                standardGSYVideoPlayer.getBackButton().setVisibility(View.GONE);
                //文本
                baseViewHolder.setText(R.id.tv_pao,videoEntity.getAuthname()+"的原创作品");
                baseViewHolder.setText(R.id.tv_caption,videoEntity.getCaption()+"");
                baseViewHolder.setText(R.id.tv_username,videoEntity.getAuthname()+"");
                baseViewHolder.setText(R.id.tv_address,videoEntity.getAddress()+"");
                //跑马灯:必须请求获得焦点，跑马灯才能跑起来
                TextView tvPao = baseViewHolder.getView(R.id.tv_pao);
                tvPao.requestFocus();
            }
                break;

        }
    }
}
